// 配置文件
var globalData = require('config.js');

//app.js
App({
    onLaunch: function () {
        var _this = this
        wx.login({
            success: function (res) {
                if (res.code) {
                    //发起网络请求
                    wx.request({
                        url: globalData.apiUrl + 'user/getopenid',
                        data: {
                            code: res.code
                        },
                        success: function (result) {
                            console.log('获取openid成功')
                            console.log(result)
                            let data = result.data.data
                            globalData.userInfo = data
                            wx.setStorageSync('user_id', data.id)
                            wx.setStorageSync('account', data.account)
                        }
                    })
                } else {
                console.log('登录失败！' + res.errMsg)
                }
            }
        })
    },
    globalData: globalData,
    //返回首页
    goToIndex: function () {
        wx.navigateTo({
            url: '../index/index'
        })
    }
})